package example.springboot.web.tests;

import freemarker.template.Configuration;
import freemarker.template.Template;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@RestController
public class ExampleSpringbootWebTestsApplication implements CommandLineRunner {

    @Autowired
    private Configuration configuration;

    public static void main(String[] args) {
        SpringApplication.run(ExampleSpringbootWebTestsApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        Template template = configuration.getTemplate("email.ftl");
        Map<String,String> params = new HashMap<>();
        params.put("name","SunApo");
        params.put("password","HaHa");
        String text = FreeMarkerTemplateUtils.processTemplateIntoString(template, params);
        System.out.println(text);
    }

    @GetMapping("test")
    public String test(){
        String resp = System.currentTimeMillis()+"ms";
        System.out.println(resp);
        return resp;
    }
}
